package net.supcmdr.dnd5e.ui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import net.supcmdr.dnd5e.AppMain;
import net.supcmdr.dnd5e.ui.AboutWindow;

@SuppressWarnings("serial")
public class MenuBar extends JMenuBar{
	
	JFrame mainFrame;
	JMenu fileMenu;
	JMenu editMenu;
	JMenu helpMenu;
	JMenuItem miCharacterPanel;
	JMenuItem closeApp;
	JMenuItem about;
	
	public MenuBar(final AppMain app, JFrame mainFrame){
		System.out.println("Initializing MenuBar...");
		
		// Add menu to the main app window/frame
		this.mainFrame = mainFrame;
		mainFrame.setJMenuBar(this);
		
		// Create and add the Menus to the Menu Bar
		fileMenu = new JMenu("File");
		editMenu = new JMenu("Edit");
		helpMenu = new JMenu("Help");
		this.add(fileMenu);
		this.add(editMenu);
		this.add(helpMenu);
		
		// Create and add the File menu items
		closeApp = new JMenuItem("Close");
		fileMenu.add(closeApp);
		
		
		// Create and add the Help menu item(s)
		about = new JMenuItem("About");
		helpMenu.add(about);
		
		
		// Add ActionListener to "Close" menu option
		closeApp.addActionListener(new ActionListener(){
			
			// Close the app when clicked
			@Override
			public void actionPerformed(ActionEvent e){
				System.exit(0);
			}
		});
		
		
		// Add ActionListener to "About" menu option
		about.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent ev){
				new AboutWindow(app);
			}
		});
	}
}
